package com.taobao.top
{
	import com.taobao.top.converter.SuiteConverter;
	/**
	 * 收费API
	 * @author 达达
	 * 
	 */	
	public class TOPSuite
	{
		public function TOPSuite()
		{
		}
		
		/**
		 * 查询套餐列表信息 
		 * @param service_code 用户订购服务的服务码(申请服务的时候会得到) 
		 * 
		 */		
		public function getSuites(service_code:String):void
		{
			var topURLLdr:TOPURLLoader = new TOPURLLoader();
			var reqParamArr:Array = new Array();
			reqParamArr=[new TopRequestParam("method","taobao.suites.get"),new TopRequestParam("service_code",service_code)];
			topURLLdr.addEventListener(Event.COMPLETE,suitsGetHandler);
			topURLLdr.loadData(reqParamArr);
		}
		
		private function suitsGetHandler(event:Event):void
		{
			switch(event.type)
			{
				case Event.COMPLETE:
					var sellerCatsArr:Array = suitsGetJsonParser(event.target.data);
					dispatchEvent(new TOPEvent(TOPEvent.TOP_DATA,sellerCatsArr));
				break;
				default:
					 dispatchEvent(event.clone());
				break;
			}
		}
		
		private function suitsGetJsonParser(jsonStr:String):void
		{
			if(TOPError.isError(jsonStr))
			{
				var topError:TOPError = TOPError.parseError(jsonStr);
				//dispatchEvent(new ErrorEvent(ErrorEvent.ERROR,false,false,
			}else
			{
				return SuiteConverter.convert((JSON.decode(jsonStr) as Object).rsp.suite);
			}
			return null;
		}
	}
}